package cn.dd.crmweb.modules.discern.uploadhistory.controller;


import cn.dd.crmweb.common.Result;
import cn.dd.crmweb.modules.discern.uploadhistory.entity.FileUploadHistory;
import cn.dd.crmweb.modules.discern.uploadhistory.mapper.FileUploadHistoryMapper;
import cn.dd.crmweb.modules.discern.uploadhistory.service.IFileUploadHistoryService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tbb
 * @since 2023-05-04
 */
@RestController
@RequestMapping("/file")
public class FileUploadHistoryController {

    @Autowired
    private FileUploadHistoryMapper historyMapper;

    @Autowired
    private IFileUploadHistoryService uploadHistoryService;

    @GetMapping("/emotion/history")
    public Result historyEmotion(@RequestParam("discernType") String discernType){
        //创建一个QueryWrapper的对象
        QueryWrapper<FileUploadHistory> wrapper = new QueryWrapper<>();
        //通过QueryWrapper设置条件
        //ge gt le lt
        //查询age>=30的记录
        //第一个参数是字段的名称 ， 第二个参数是设置的值
        wrapper.eq("discern_type" , discernType);
        List<FileUploadHistory> historyList = historyMapper.selectList(wrapper);

        return Result.success(historyList);
    }

    @PostMapping("/upload/history")
    public Result uploadHistory(@RequestBody FileUploadHistory uploadHistory){
        historyMapper.insert(uploadHistory);
        return Result.success();
    }

    @GetMapping("/delete/history/one")
    public Result deleteHistoryOne(@RequestParam("fid") String fid){
        historyMapper.deleteById(fid);
        return Result.success();
    }

    @GetMapping("/delete/history/all")
    public Result deleteHistoryAll(){
        uploadHistoryService.remove(new QueryWrapper<>());
        return Result.success();
    }
}

